package org.hk.controller;

import org.hk.dao.AdminDao;
import org.hk.entity.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.annotation.WebServlet;
import java.sql.SQLException;
import java.util.List;

@Controller //@Controller @Service @Repository @Component
@RequestMapping("/adminController")
public class AdminController //extends HttpServlet
{
    @Autowired
    AdminDao adminDao;// dao 不 new但是能够使用是因为 spring的ioc（invers of controll 反转控制，对象的生成由容器（小容器spring 大容器tomcat）完成） 生成了对象

    public AdminDao getAdminDao() {
        return adminDao;
    }

    public void setAdminDao(AdminDao adminDao) {
        this.adminDao = adminDao;
    }

    public AdminController() throws IllegalAccessException, SQLException, ClassNotFoundException {
    }
    @RequestMapping("/getAll")
    @ResponseBody
    public String getAll() throws IllegalAccessException, SQLException, InstantiationException {
        List<Admin> admins = adminDao.getAllAdmin();
//        StringBuilder adminsStr = new StringBuilder();
//        for (Admin admin : admins) {
//            adminsStr.append(admin.toString());//我们覆盖了admin的toString方法
//        }
        return "getAll";
    }
    @RequestMapping("/update")
    @ResponseBody
    public String update() throws IllegalAccessException, SQLException, InstantiationException {
        List<Admin> admins = adminDao.getAllAdmin();
//        StringBuilder adminsStr = new StringBuilder();
//        for (Admin admin : admins) {
//            adminsStr.append(admin.toString());//我们覆盖了admin的toString方法
//        }
        return "update";
    }
}
